/**
 * 
 */
package us.gaaoc.framework.webapp.backingbeans.clerk;

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Map;

import javax.faces.context.FacesContext;

import us.gaaoc.framework.model.CourtHearingNegotiations;
import us.gaaoc.framework.model.Person;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * 
 * @author hea
 * @date Apr 25, 2006
 * @version: GAJE 1.5
 *
 */ 
@SuppressWarnings("unchecked")
public class AcceptCourtDateConfirmationPage extends BaseBackingBean {

	/**
	 * Properties
	 */
	
	/** Generated Serial Version UID */
	private static final long serialVersionUID = 1364211890335574263L;
	private CourtHearingNegotiations courtHearingNegotiations;
	private Date scheduledCourtDate;
	private Date proposedCourtDate;	
	private String caseUuid;
	private String docketID;
	
	/**
	 * Constructor
	 *
	 */
	public AcceptCourtDateConfirmationPage(){
		String courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		this.setCourtHearingNegotiations(this.getModelFacade().findCourtHearingNegotiationsByCaseRecordUuid(this.getCaseUuid()));
		this.setProposedCourtDate(this.getCourtHearingNegotiations().getProposedCourtDate());
		this.setScheduledCourtDate(this.getCourtHearingNegotiations().getPreviousCourtDate());
		this.setDocketID(this.getModelFacade().findCaseRecordById(this.getCaseUuid(), courtUuid).getCaseTrackingId());
	}
	
	/**
	 * Getter for property caseUuid
	 * @return caseUuid
	 */
	public String getCaseUuid() {
		return caseUuid;
	}
	
	/**
	 * Setter for property caseUuid
	 * @param caseUuid
	 */
	public void setCaseUuid(String caseUuid) {
		this.caseUuid = caseUuid;
	}	
	
	/**
	 * Getter for property courtHearingNegotiations
	 * @return courtHearingNegotiations
	 */
	public CourtHearingNegotiations getCourtHearingNegotiations() {
		return courtHearingNegotiations;
	}

	/**
	 * Setter for property courtHearingNeotiations
	 * @param chn
	 */
	public void setCourtHearingNegotiations(CourtHearingNegotiations chn) {
		this.courtHearingNegotiations = chn;
	}
	
	/**
	 * Getter for property proposedCourtDate
	 * @return proposedCourtDate
	 */
	public Date getProposedCourtDate() {
		return proposedCourtDate;
	}
	
	/**
	 * Setter for property proposedCourtDate
	 * @param proposedCourtDate
	 */
	public void setProposedCourtDate(Date proposedCourtDate) {
		this.proposedCourtDate = proposedCourtDate;
	} 
	
	/**
	 * This method gets called when the user confirms the courtDate.
	 * After accepting this method sends the confirmed date to the Client and
	 * insert the data into the mySQL database
	 * @return String
	 */
	public String confirm() {
		/** 
		 * 1.send response to the client that proposed date is accepted.
		 * 2.insert into the data model.
		 * 
		 */
		
		GregorianCalendar scheduleDate = new GregorianCalendar();
		GregorianCalendar proposedDate = new GregorianCalendar();
		scheduleDate.setTime(this.getScheduledCourtDate());
		proposedDate.setTime(this.getProposedCourtDate());
		
		try {
			// TODO add email notification!!!!!!!!!!!
		} catch (Exception e) {			
			e.printStackTrace();
		} 
		this.getModelFacade().updateCourtHearingNegotiationStausToAccepted(this.getCourtHearingNegotiations());
		
		Map sessionMap = this.getFacesContext().getExternalContext()
			.getSessionMap();
		Person updatePerson = (Person) sessionMap.get("person");
		String updatePersonUuid = updatePerson.getUuid();
		this.getModelFacade().updateCourtDate(this.getCaseUuid(), this.getProposedCourtDate(), updatePersonUuid);
		return "gotoCaseDetailsPage";
	}	

	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	public String back() {
		return "gotoCaseDetailsPage";
	}

	/**
	 * Getter scheduledCourtDate
	 * @return scheduledCourtDate
	 */
	public Date getScheduledCourtDate() {
		return scheduledCourtDate;
	}

	/**
	 * Setter for property scheduledCourtDate
	 * @param scheduledCourtDate
	 */
	public void setScheduledCourtDate(Date scheduledCourtDate) {
		this.scheduledCourtDate = scheduledCourtDate;
	}

	/**
	 * Getter for property docketID
	 * @return docketID
	 */
	public String getDocketID() {
		return docketID;
	}

	/**
	 * Setter for property docketID
	 * @param docketID
	 */
	public void setDocketID(String docketID) {
		this.docketID = docketID;
	}	 
}
